import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 5173,
    proxy: {
      //获取了路径中包含/api的请求，并将其转发到http://localhost:8080
      '/api': {
        //target: 'http://175.178.50.24:8080',//目标服务器地址
        target: 'http://localhost:8080',//目标服务器地址
        changeOrigin: true,//允许跨域，修改源地址
        rewrite: (path) => path.replace(/^\/api/, '')//重写路径，相当于api替换为‘’
      }
    }
  }
})
